package controllers

import (
	"read.com/admin/models"
	"read.com/admin/libs"
)

type OrderController struct {
	BaseController
}

func (self *OrderController) List() {
	self.Data["pageTitle"] = "订单列表"
	appList,_ := models.GetAllSysApp()
	self.Data["app"] = appList
	total := models.GetAllCount()
	common := models.GetVipCount()
	dayProfit := models.GetDayProfit()
	weekProfit := models.GetWeekProfit()
	monthProfit := models.GetMonthProfit()
	totalProfit := models.GetTotalProfit()
	self.Data["total"] = total
	self.Data["vip"] = total - common
	self.Data["common"] = common
	self.Data["dayProfit"] = dayProfit
	self.Data["weekProfit"] = weekProfit
	self.Data["monthProfit"] = monthProfit
	self.Data["totalProfit"] = totalProfit
	self.display()
}

func (self *OrderController) Table() {
	start := self.GetString("startTime")
	end := self.GetString("endTime")
	appId,_ := self.GetInt("appId")
	//列表参数
	page, err := self.GetInt("page")
	if err != nil {
		page = 1
	}
	limit, err := self.GetInt("limit")
	if err != nil {
		limit = 10
	}

	orderList, total,tableHead := models.GetOrderList(page,limit,start,end,appId)

	export := self.GetString("export")
	if export == "1" { // 导出excel格式
		libs.FormatExcel(self.Ctx.Output, orderList,tableHead)
	} else { // 查询
		self.ajaxList("成功", MSG_OK, total, orderList)
	}
	self.ajaxList("成功", MSG_OK, total, orderList)
}